<template>
<div class="assetstotal">
    <section class="totalmain">
        <ul class="totalheader">
            <li class="list">
                <img src="../../assets/img/zzc-img.png" alt="">
                <h2 class="listh2">{{$t('total[0]')}}</h2>
                <h3 class="listh3">
                    <span class="h2">{{assetInfodata.total_usdt-0}}</span>
                    <span class="h3">USDT</span>
                    <span class="h4">≈{{assetInfodata.total_cny-0}} CNY</span>
                </h3>
            </li>
            <li class="list" v-if="false">
                <router-link to="giftdetailed" class="listh4" tag="h2">
                    <span>{{$t('gift[4]')}} ></span>
                </router-link>
                <h3 class="listh5">
                    <span>{{gift.balance}} USDT</span>
                </h3>
            </li>
        </ul>

        <ul class="rechargeheadere">
            <li class="h1">{{$t('total[1]')}}</li>
            <li class="h2">{{$t('total[2]')}}</li>
            <li class="h3">{{$t('total[3]')}}</li>
        </ul>

        <ul class="rechargemian" v-for="(item, index) in assetInfodata.asset_list" :key="index">
            <li class="h1">{{item.code}}</li>
            <li class="h2">{{item.balance}}</li>
            <li class="h3">{{item.frost}}</li>
        </ul>
        <section class="footerbut">
            <a class="assetsrecharge" v-if="$route.query.type==3" @click="change_router('assetsrecharge')">{{$t('total[4]')}}</a>
            <a class="assetswithdraw" v-if="$route.query.type==3" @click="change_router('assetswithdraw')">{{$t('total[5]')}}</a>
            <a class="assetstransfer" @click="change_router('assetstransfer')">{{$t('total[13]')}}</a>
        </section>

        <section class="footerheader">
            <h2>{{$t('total[6]')}}</h2>
            <router-link :to="'/assetsdetailed?type='+$route.query.type">{{$t('total[7]')}}</router-link>
        </section>
        <section class="footertotal">
            <el-table :data="indexdata.data" style="width: 100%">
                <el-table-column prop="name" :label="$t('total[8]')" width="140" align="left">
                    <template>
                        <span>USDT</span>
                    </template>
                </el-table-column>
                <el-table-column prop="money" :label="$t('total[9]')" width="350" align="right">
                </el-table-column>
                <el-table-column prop="mark" :label="$t('total[10]')" width="350" align="right">
                </el-table-column>
                <el-table-column prop="created_at" :label="$t('total[11]')" width="348" align="right">
                </el-table-column>
            </el-table>
        </section>
    </section>
</div>
</template>

<script>
import {
    assetInfo,
    details
} from '@/api/user'
import {
    userMoneyLog,
    giftasset
} from '@/api/assetstotal'
// import { mapActions } from 'vuex'
// import { setToken } from "@/libs/util";
export default {
    name: 'assetstotal',
    data() {
        return {
            assetInfodata: {
                total_usdt: 0,
                total_cny: 0,
                asset_list: []
            },
            indexdata: "",
            userinfo: '',
            gift: {},
            accountTpye: ''
        }
    },
    watch: {
        $route(to, from) {
            this.$router.go(0)
        }
    },
    methods: {
        change_router(which) {
            if (which == 'assetsrecharge') {
                this.$router.push({
                    path: which
                })
            }
            if (which == 'assetswithdraw') {
                if (this.userinfo.config.phone_bind != 1) {
                    this.$message.error(this.$t('fabi.Tips[3]'));
                    return false;
                }
                if (this.userinfo.user.authentication == 0) {
                    this.$message.error(this.$t('fabi.Tips[4]'));
                    return false;
                }
                if (this.userinfo.config.payment_password_set != 1) {
                    this.$message.error(this.$t('fabi.Tips[7]'));
                    return false;
                }
                this.$router.push({
                    path: which
                })
            }
            if (which == 'assetstransfer') {
                if (this.userinfo.config.phone_bind != 1) {
                    this.$message.error(this.$t('fabi.Tips[3]'));
                    return false;
                }
                if (this.userinfo.config.payment_password_set != 1) {
                    this.$message.error(this.$t('fabi.Tips[7]'));
                    return false;
                }
                this.$router.push({
                    name: which,
                    query: {
                        type: this.accountTpye
                    }
                })
            }
        },
        getdata() {
            assetInfo({
                account: this.$route.query.type
            }).then(res => {

                this.assetInfodata = res;
                userMoneyLog({
                    wid: res.asset_list[0].wid,
                    account: this.$route.query.type
                }).then(res => {
                    if (res.data.status_code == 200) {
                        this.indexdata = res;
                    }
                }).catch(err => {});

            }).catch(err => {});
        },
        getgift() {
            giftasset({
                wid: 1
            }).then(res => {

                this.gift = res;

            }).catch(err => {});
        }
    },
    mounted() {
        this.getdata();
        this.getgift();
        this.accountTpye = this.$route.query.type
        details().then(res => {

            this.userinfo = res

        }).catch(err => {});
    },
}
</script>
